﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;

namespace Function
{
    public class MessageBox
    {
        private MessageBoxBase lhg = new MessageBoxBase();

        #region 普通提示框
        /// <summary>
        /// 提醒消息提示框
        /// </summary>
        /// <param name="page"></param>
        /// <param name="Msg">消息</param>
        public void AlertBox(Page page, string Msg, bool parentJump = false, bool isScript = false)
        {
            if (!page.ClientScript.IsClientScriptBlockRegistered(page.GetType(), "keys"))
            {
                page.ClientScript.RegisterClientScriptBlock(page.GetType(), "keys", lhg.CommonDialog(MessageBoxBase.MessType.Alarm, Msg, "", parentJump, isScript));
            }
        }

        /// <summary>
        /// 提醒消息提示框
        /// </summary>
        /// <param name="page"></param>
        /// <param name="Msg">消息</param>
        /// <param name="url">链接地址 留空则跳到当前页面</param>
        public void AlertBox(Page page, string Msg, string url, bool parentJump = false, bool isScript = false)
        {
            if (url.IsEmpty())
                url = Method.GetScriptName;
            if (!page.ClientScript.IsClientScriptBlockRegistered(page.GetType(), "keys"))
            {
                page.ClientScript.RegisterClientScriptBlock(page.GetType(), "keys", lhg.CommonDialog(MessageBoxBase.MessType.Alarm, Msg, url, parentJump, isScript));
            }
        }

        /// <summary>
        /// 错误消息提示框
        /// </summary>
        /// <param name="page"></param>
        /// <param name="Msg">消息</param>
        public void ErrorBox(Page page, string Msg, bool parentJump = false, bool isScript = false)
        {
            if (!page.ClientScript.IsClientScriptBlockRegistered(page.GetType(), "keys"))
            {
                page.ClientScript.RegisterClientScriptBlock(page.GetType(), "keys", lhg.CommonDialog(MessageBoxBase.MessType.Error, Msg, "", parentJump, isScript));
            }
        }

        /// <summary>
        /// 错误消息提示框
        /// </summary>
        /// <param name="page"></param>
        /// <param name="Msg">消息</param>
        /// <param name="url">链接地址 留空则跳到当前页面</param>
        public void ErrorBox(Page page, string Msg, string url, bool parentJump = false, bool isScript = false)
        {
            if (url.IsEmpty())
                url = Method.GetScriptName;
            if (!page.ClientScript.IsClientScriptBlockRegistered(page.GetType(), "keys"))
            {
                page.ClientScript.RegisterClientScriptBlock(page.GetType(), "keys", lhg.CommonDialog(MessageBoxBase.MessType.Error, Msg, url, parentJump, isScript));
            }
        }

        /// <summary>
        /// 成功消息提示框
        /// </summary>
        /// <param name="page"></param>
        /// <param name="Msg">消息</param>
        public void SuccessBox(Page page, string Msg, bool parentJump = false, bool isScript = false)
        {
            if (!page.ClientScript.IsClientScriptBlockRegistered(page.GetType(), "keys"))
            {
                page.ClientScript.RegisterClientScriptBlock(page.GetType(), "keys", lhg.CommonDialog(MessageBoxBase.MessType.Success, Msg, "", parentJump, isScript));
            }
        }

        /// <summary>
        /// 成功消息提示框
        /// </summary>
        /// <param name="page"></param>
        /// <param name="Msg">消息</param>
        /// <param name="url">链接地址 留空则跳到当前页面</param>
        public void SuccessBox(Page page, string Msg, string url, bool parentJump = false, bool isScript = false)
        {
            if (url.IsEmpty())
                url = Method.GetScriptName;
            if (!page.ClientScript.IsClientScriptBlockRegistered(page.GetType(), "keys"))
            {
                page.ClientScript.RegisterClientScriptBlock(page.GetType(), "keys", lhg.CommonDialog(MessageBoxBase.MessType.Success, Msg, url, parentJump, isScript));
            }
        }

        public void ErrorBox(Control ctr, string Msg, bool parentJump = false, bool isScript = false)
        {
            ScriptManager.RegisterStartupScript(ctr, ctr.GetType(), "ErrorBox", lhg.CommonDialog(MessageBoxBase.MessType.Error, Msg, "", parentJump, isScript), false);

        }

        public void SuccessBox(Control ctr, string Msg, string url, bool parentJump = false, bool isScript = false)
        {
            ScriptManager.RegisterStartupScript(ctr, ctr.GetType(), "SuccessBox", lhg.CommonDialog(MessageBoxBase.MessType.Success, Msg, url, parentJump, isScript), false);

        }
        #endregion

        #region 倒计时提示框
        /// <summary>
        /// 倒计时成功提示框
        /// </summary>
        /// <param name="page">当前页面</param>
        /// <param name="Msg">提示消息</param>
        /// <param name="timeInSeconds">倒计时秒数</param>
        /// <param name="parentJump">是否为父级容器对象跳转</param>
        /// <param name="isScript">是否执行自定义代码</param>
        public void SuccessTimingBox(Page page, string Msg, int timeInSeconds = 2, bool parentJump = false, bool isScript = false)
        {
            if (!page.ClientScript.IsClientScriptBlockRegistered(page.GetType(), "keys"))
            {
                page.ClientScript.RegisterClientScriptBlock(page.GetType(), "keys", lhg.TimingDialog(MessageBoxBase.MessType.Success, Msg, timeInSeconds, "", parentJump, isScript));
            }
        }

        /// <summary>
        /// 倒计时成功提示框
        /// </summary>
        /// <param name="page">当前页面</param>
        /// <param name="Msg">提示消息</param>
        /// <param name="timeInSeconds">倒计时秒数</param>
        /// <param name="url">跳转地址</param>
        /// <param name="parentJump">是否为父级容器对象跳转</param>
        /// <param name="isScript">是否执行自定义代码</param>
        public void SuccessTimingBox(Page page, string Msg, string url, int timeInSeconds = 2, bool parentJump = false, bool isScript = false)
        {
            if (url.IsEmpty())
                url = Method.GetScriptName;
            if (!page.ClientScript.IsClientScriptBlockRegistered(page.GetType(), "keys"))
            {
                page.ClientScript.RegisterClientScriptBlock(page.GetType(), "keys", lhg.TimingDialog(MessageBoxBase.MessType.Success, Msg, timeInSeconds, url, parentJump, isScript));
            }
        }

        /// <summary>
        /// 倒计时失败提示框
        /// </summary>
        /// <param name="page">当前页面</param>
        /// <param name="Msg">提示消息</param>
        /// <param name="timeInSeconds">倒计时秒数</param>
        /// <param name="parentJump">是否为父级容器对象跳转</param>
        /// <param name="isScript">是否执行自定义代码</param>
        public void ErrorTimingBox(Page page, string Msg, int timeInSeconds = 2, bool parentJump = false, bool isScript = false)
        {
            if (!page.ClientScript.IsClientScriptBlockRegistered(page.GetType(), "keys"))
            {
                page.ClientScript.RegisterClientScriptBlock(page.GetType(), "keys", lhg.TimingDialog(MessageBoxBase.MessType.Error, Msg, timeInSeconds, "", parentJump, isScript));
            }
        }

        /// <summary>
        /// 倒计时失败提示框
        /// </summary>
        /// <param name="page">当前页面</param>
        /// <param name="Msg">提示消息</param>
        /// <param name="timeInSeconds">倒计时秒数</param>
        /// <param name="url">跳转地址</param>
        /// <param name="parentJump">是否为父级容器对象跳转</param>
        /// <param name="isScript">是否执行自定义代码</param>
        public void ErrorTimingBox(Page page, string Msg, string url, int timeInSeconds = 2, bool parentJump = false, bool isScript = false)
        {
            if (url.IsEmpty())
                url = Method.GetScriptName;
            if (!page.ClientScript.IsClientScriptBlockRegistered(page.GetType(), "keys"))
            {
                page.ClientScript.RegisterClientScriptBlock(page.GetType(), "keys", lhg.TimingDialog(MessageBoxBase.MessType.Error, Msg, timeInSeconds, url, parentJump, isScript));
            }
        }

        /// <summary>
        /// 倒计时警告提示框
        /// </summary>
        /// <param name="page">当前页面</param>
        /// <param name="Msg">提示消息</param>
        /// <param name="timeInSeconds">倒计时秒数</param>
        /// <param name="parentJump">是否为父级容器对象跳转</param>
        /// <param name="isScript">是否执行自定义代码</param>
        public void AlertTimingBox(Page page, string Msg, int timeInSeconds = 2, bool parentJump = false, bool isScript = false)
        {
            if (!page.ClientScript.IsClientScriptBlockRegistered(page.GetType(), "keys"))
            {
                page.ClientScript.RegisterClientScriptBlock(page.GetType(), "keys", lhg.TimingDialog(MessageBoxBase.MessType.Alarm, Msg, timeInSeconds, "", parentJump, isScript));
            }
        }

        /// <summary>
        /// 倒计时警告提示框
        /// </summary>
        /// <param name="page">当前页面</param>
        /// <param name="Msg">提示消息</param>
        /// <param name="timeInSeconds">倒计时秒数</param>
        /// <param name="url">跳转地址</param>
        /// <param name="parentJump">是否为父级容器对象跳转</param>
        /// <param name="isScript">是否执行自定义代码</param>
        public void AlertTimingBox(Page page, string Msg, string url, int timeInSeconds = 2, bool parentJump = false, bool isScript = false)
        {
            if (url.IsEmpty())
                url = Method.GetScriptName;
            if (!page.ClientScript.IsClientScriptBlockRegistered(page.GetType(), "keys"))
            {
                page.ClientScript.RegisterClientScriptBlock(page.GetType(), "keys", lhg.TimingDialog(MessageBoxBase.MessType.Alarm, Msg, timeInSeconds, url, parentJump, isScript));
            }
        }
        #endregion
    }
}
